package com.dzsw.mail;

import org.yaml.snakeyaml.Yaml;

import java.io.BufferedReader;
import java.io.IOException;
import java.net.URL;
import java.nio.file.FileSystems;
import java.nio.file.Files;
import java.nio.file.Path;
import java.security.CodeSource;
import java.security.ProtectionDomain;
import java.util.Map;

public class YmlExample {

    public static void main(String[] args) throws IOException {
        Yaml yaml = new Yaml();
        Path path = FileSystems.getDefault().getPath("D:\\mail.yml");
        try (BufferedReader reader = Files.newBufferedReader(path)) {
            ResendMailConfig config = yaml.loadAs(reader, ResendMailConfig.class);
            System.out.println(config.toString());
        }
        Map<String, String> map = System.getenv();
        for (Map.Entry<String, String> entry : map.entrySet()) {
            System.out.println(entry.getKey() + " : " + entry.getValue());
        }

        ProtectionDomain protectionDomain = YmlExample.class.getProtectionDomain();
        CodeSource codeSource = protectionDomain.getCodeSource();
        URL location = codeSource.getLocation();
        String jarPath = location.getPath();
        System.out.println("JAR Path: " + location.getPath());
        /** yml
         * smtpHost: smtp.exmail.qq.com
         * smtpPort: 465
         * userName: sunzhe@sy-binal.com
         * password: LmUmTJ7bjZdbjRXy
         * toList:
         *   - sunzhe@sy-binal.com
         *   - sunzhe@sy-binal.com
         *   - sunzhe@sy-binal.com
         */
    }
}
